package com.zcf.utils.zhifubao;

import com.alipay.api.AlipayApiException;
import com.alipay.api.DefaultAlipayClient;

import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * @author 颠覆白的黑
 * @version 创建时间：2018年3月26日 下午5:29:31
 * 类说明
 */
public class transfer {
    public static void main(String[] args) {
    }

    //配置初始化信息参数
    public static DefaultAlipayClient alipayclient() {
        DefaultAlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",
                ALiPayConfig.appid, ALiPayConfig.private_key, "json",
                ALiPayConfig.input_charset, ALiPayConfig.ali_public_key,
                "RSA2");
        return alipayClient;
}

    //单笔转账到支付宝账户
//    public static int AlipayFundTransToaccountTransfer(String realname, Double money, String alicount, String alicount2) throws AlipayApiException {
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
//        Date date = new Date();
//        String logtDate = sdf.format(date)
//                + (int) (Math.random() * 9) + (int) (Math.random() * 9);
//    }
}
//        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", ALiPayConfig.appid, ALiPayConfig.private_key, "json", "GBK", ALiPayConfig.ali_public_key, "RSA2");
//        //AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",
//        // ALiPayConfig.appid, ALiPayConfig.private_key,"D:\\Download\\appCertPublicKey_2021001170608240.crt",
//        // "D:\\Download\\alipayCertPublicKey_RSA2.crt",
//        // "D:\\Download\\alipayRootCert.crt",
//        // "utf-8","RSA2");
//        AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest();
//        request.setBizContent("{" +
//                "\"out_biz_no\":\"" + logtDate + "\"," +
//                "\"payee_type\":\"ALIPAY_LOGONID\"," +
//                "\"payee_account\":\"" + alicount + "\"," +
//                "\"amount\":\"12.23\"," +
//                "\"payer_show_name\":\"批量付款\"," +
//                "\"payee_real_name\":\"" + realname + "\"," +
//                "\"remark\":\"提现\"" +
//                "  }");
//        AlipayFundTransToaccountTransferResponse response = null;
//        try {
//
//            response = alipayClient.execute(request);
//
//            if (response.isSuccess()) {
//                System.out.println("调用成功");
//            } else {
//                System.out.println("调用失败");
//            }
//
//        } catch (AlipayApiException e) {
//            e.printStackTrace();
//        }
//        if (response.isSuccess()) {
//            return 1;
//        } else {
//            return 2;
//        }
//开始
//        CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
//        certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do");  //gateway:支付宝网关（固定）https://openapi.alipay.com/gateway.do
//        certAlipayRequest.setAppId(ALiPayConfig.appid);  //APPID 即创建应用后生成,详情见创建应用并获取 APPID
//        certAlipayRequest.setPrivateKey(ALiPayConfig.private_key);  //开发者应用私钥，由开发者自己生成
//        certAlipayRequest.setFormat("json");  //参数返回格式，只支持 json 格式
//        certAlipayRequest.setCharset("utf-8");  //请求和签名使用的字符编码格式，支持 GBK和 UTF-8
//        certAlipayRequest.setSignType("RSA2");  //商户生成签名字符串所使用的签名算法类型，目前支持 RSA2 和 RSA，推荐商家使用 RSA2。
//        certAlipayRequest.setCertPath(ALiPayConfig.app_cert_path); //应用公钥证书路径（app_cert_path 文件绝对路径）
//        certAlipayRequest.setAlipayPublicCertPath(ALiPayConfig.alipay_cert_path); //支付宝公钥证书文件路径（alipay_cert_path 文件绝对路径）
//        certAlipayRequest.setRootCertPath(ALiPayConfig.alipay_root_cert_path);  //支付宝CA根证书文件路径（alipay_root_cert_path 文件绝对路径）
//        AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);
//        AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest ();
//        request.setBizContent("{" +
//                "\"out_biz_no\":\"" + logtDate + "\"," +
//                "\"trans_amount\":\""+money+"\"," +
//                "\"product_code\":\"TRANS_ACCOUNT_NO_PWD\"," +
//                "\"biz_scene\":\"DIRECT_TRANSFER\"," +
//                "\"order_title\":\"提现\"," +
//                "\"payee_info\":{" +
//                "\"identity\":\""+alicount+"\"," +
//                "\"identity_type\":\"ALIPAY_LOGON_ID\"," +
//                "\"name\":\""+alicount2+"\"" +
//                "}," +
//                "\"remark\":\"小鸡外卖提现\"," +
//                "\"business_params\":{\"payer_show_name\":\"小鸡外卖\"}"+"}");
//        //发送API请求
//        AlipayFundTransUniTransferResponse response = null;
//
//                response = alipayClient.certificateExecute(request);
//        if (response.isSuccess()) {
//            System.out.println("调用成功");
//            return 1;
//        } else {
//            System.out.println("调用失败");
//            return 2;
//        }
//    }

//  {"alipay_fund_trans_toaccount_transfer_response":{"code":"40004","msg":"Business Failed","sub_code":
//	  "PAYEE_NOT_EXIST","sub_msg":"收款账号不存在","out_biz_no":"2019022710170224"},
//	  "sign":"Fri7KbRxrgI1V5QxwXlQFcGjKXXglDqdzPeCxU+Uw3bRaZsy0PWTELq43I/hsSLoEbKz7vKb4MfRr9jwTdX7SbT8B5ZAIsCb86nKPxQbXNatDCm54mQEHuvyy/KFBBBtcwEei/DSHh/iS4ZM2mH2SrHb8wPJ0l2/gd5ogHtFFLkV07w6DunUG2F0KC+Glmlk4DC8KIQ4NudhBupTTUZ0JyxO1inVzJRfPy3Ms8T4zlX+Wq7U5bA2mQcBrRnO0d6j+gGd3EjnP3T3M61vPalPH1CkI5mo/nc2CAzuGRmtYxraNFqlf1And58wO5Adx2iqTNCDhHSJ5lCPddGv4S56Rg=="}
//
//
